import CryptoJS from 'crypto-js';
let key = CryptoJS.enc.Utf8.parse("9f5e7e5187174a39");
let iv = CryptoJS.enc.Utf8.parse("9f5e7e5187174a39");
// let key = CryptoJS.enc.Utf8.parse("1234567890123456");
// let iv = CryptoJS.enc.Utf8.parse("1234567890123456");
// 加密
let encrypt=function (text) {
	return CryptoJS.AES.encrypt(text, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7,
	});
}

// 解密
let decrypt=function (text) {
	let r=CryptoJS.AES.decrypt(text, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7,
	}).toString(CryptoJS.enc.Utf8);
	let timeReg = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/g;
	r = r.replace(timeReg, function ($all) {
		return $all.replace('T',' ');
	});
	return JSON.parse(r);
}

export default {
	encrypt: encrypt,
	decrypt: decrypt,
}